<template>
	<view style="background-color: #edf1f4">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
			:up="upOption">
			<view class="Item" style="margin-top: 30rpx;">
				<view class="item-link item-content">
					<view class="item-inner">

						<view class="item-text">
							<view class="ispan">
								<image src="../../static/images/icon-bitian.png" class="item-icon-bt" mode="">资产名称：
							</view>
							<view class="span">
								<input type="text" v-model="assetName" placeholder="请输入资产名称"
									placeholder-class="inputff" />
							</view>
						</view>
						<view class="item-text">
							<view class="ispan">
								<image src="../../static/images/icon-bitian.png" class="item-icon-bt" mode="">资产类别：
							</view>
							<view class="span">
								<view @tap="focusshow($event)" data-id="zclb" class="inputff">{{inputzclb}}</view>

							</view>
						</view>
						<view class="item-text">
							<view class="ispan">
								<image src="../../static/images/icon-bitian.png" class="item-icon-bt" mode="">存放位置：
							</view>
							<view class="span">
								<view @tap="focusshow($event)" data-id="zcwz" class="inputff">{{inputzcwz}}</view>
							</view>
						</view>
						<view class="item-text">
							<view class="ispan">
								<image src="../../static/images/icon-bitian.png" class="item-icon-bt" mode="">规格型号：
							</view>
							<view class="span">
								<input type="text" v-model="GGXH" placeholder="请输入规格型号" placeholder-class="inputff" />
							</view>
						</view>
						<view class="item-text">
							<view class="ispan">
								<image src="../../static/images/icon-bitian.png" class="item-icon-bt" mode="">使用人：
							</view>
							<view class="span">
								<input type="text" v-model="assetUsingName" placeholder="请输入使用人" placeholder-class="inputff" />
							</view>
						</view>
						<!--view class="item-text">
							<view class="ispan">
								<image src="../../static/images/icon-bitian.png" class="item-icon-bt" mode="">使用部门：
							</view>
							<view class="span">
								<view @tap="focusshow($event)" data-id="sybm" class="inputff">{{inputsybm}}</view>
							</view>
						</view>
						<view class="item-text">
							<view class="ispan">
								<image src="../../static/images/icon-bitian.png" class="item-icon-bt" mode="">使用人：
							</view>
							<view class="span">
								<view @tap="focusshow($event)" data-id="syr" class="inputff">{{inputsyr}}</view>
							</view>
						</view-->

						<view class="item-text">
							<view class="ispan">
								<image class="item-icon-bt" mode="">盘点日期：
							</view>
							<view class="span">
								{{getDateDayStr(this.iputewdate)}}
							</view>
						</view>
						<view class="item-text">
							<view class="ispan">
								<image class="item-icon-bt" mode="">盘点结果：
							</view>
							<view class="span">
								盘盈
							</view>
						</view>
						<view class="item-text">
							<view class="ispan">
								<image class="item-icon-bt" mode="">盘点备注：
							</view>
							<view class="span">
								<input type="text" v-model="assetDescription" placeholder="请输入盘点备注信息"
									placeholder-class="inputff" />
							</view>
						</view>
						<view class="item-text"
						 style="height: 210rpx;margin-top:80rpx !important;background-color: #fff;">
							<view class="ispan"><image :src="getbt()" class="item-icon-bt" mode=""></image>盘点照片：</view>
							<view class="span">
								
								<image :src="getvalues()" class="item-icon" 
								mode="" @tap="uploadimg()"></image>
							</view>		
						</view>

					</view>

				</view>
			</view>
		</mescroll-body>
		<tki-tree ref="tkitree" :selectParent="selectParent" :multiple="multiple" :range="treelist" :foldAll="flod"
			rangeKey="Name" :title="title" @confirm="treeConfirm" @cancel="treeCancel" :selectvalue="selectvalue" @KeyInput="treekeyinput"></tki-tree>
	</view>
</template>

<script>
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"
	import tkiTree from '@/components/tki-tree-asset/tki-tree.vue';
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	import {
		openComDB,
		executeSQL,
		dropSQL
	} from "@/pages/API/sqllite/sqllite.js";
	var self;
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			MescrollBody,
			MescrollUni,
			tkiTree
		},
		data() {
			return {
				downOption: {
					native: false,
					beforeEndDownScroll: 1000,
					textInOffset: "下拉刷新",
					textOutOffset: "释放刷新",
					textLoading: "加载中..."
				},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 6 // 每页数据的数量,默认10
					},
					noMoreSize: 3, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					},
					toTop: {
						src: "../../static/images/totop.png",
						offset: 50,
						duration: 300,
						zIndex: 9990,
						right: 20,
						bottom: 120,
						safearea: false,
						width: 72,
						radius: "50%",
						left: null
					},
				},
				model: {},
				omodel: {},
				documentmodel: {},
				loginName: "",
				loginid: "",
				loginorgId:"",
				currAddress: "上海市",
				DocumentId: "",
				AssetCode: "",
				images: [],
				srcstring: "../../static/images/icon-paizhao.png",
				srcsys: "../../static/images/icon-sys-hui.png",
				scrbt: "../../static/images/icon-bitian.png",
				assetCode: "",
				assetName: "",
				GGXH: "",
				assetCodeTitle: "",
				stockDate: "确认盘点后自动更新",
				optiontype: "0",
				storeId: "",
				storeName: "",
				statuArray: ['正常', '异常', '盘盈'],
				statuResultArray: ['位置异常', '名称异常', '标签异常'],
				statuindex: 0,
				statuResultindex: 0,
				statuResult: '',
				assetDescription: "盘盈",
				assetUsingName: "",
				CurrentUserName: "",
				CurrentUserRoleName: "",
				CurrentDepartmentName: "",
				CurrentStoreName: "",
				CurrentStoreId: "",
				inputzclb: "请选择资产类别 >",
				inputzcwz: "请选择资产位置 >",
				inputsybm: "请选择使用部门 >",
				inputsyr: "请选择使用人 >",
				inputzclbid: "",
				inputzcwzid: "",
				inputpdzcwz: "",
				inputpdzcwzid: "",
				inputsybmid: "",
				inputsyrid: "",
				iputewdate: "",
				treelist: [],
				multiple: false,
				selectParent: true,
				flod: false,
				title: "选择资产位置",
				titleColor: "#6D8AF9",
				showTreeValue: false,
				inputzclbid: "",
				inputzcwzid: "",
				inputpdzcwz: "",
				inputpdzcwzid: "",
				inputsybmid: "",
				inputsyrid: "",
				isrequest:true,
				isPhoto:"0",
			}
		},
		onBackPress(options) {
			return false;
		},
		onNavigationBarButtonTap() {
			{
			
				self = this;
				const newDocumentId = uni.getStorageSync('DocumentId');
				const userinfo = uni.getStorageSync("userInfo");
				let username=JSON.parse(userinfo).userName;
				console.log(username);
				uni.setStorage({
					key: "shuaxinDate",
					data: "1"
				});
				if(self.assetName==""){
					uni.showToast({
						icon: 'none',
						title: '请输入资产名称'
					});
					return;
				}
				if(self.GGXH==""){
					uni.showToast({
						icon: 'none',
						title: '请输入规格型号'
					});
					return;
				}
				if(self.assetUsingName==""){
					uni.showToast({
						icon: 'none',
						title: '请输入使用人'
					});
					return;
				}
				if(self.inputzclbid==""){
					uni.showToast({
						icon: 'none',
						title: '请选择资产类别'
					});
					return;
				}
				
				
				
				//if(self.inputsyrid==""){
				//	uni.showToast({
				//		icon: 'none',
				//		title: '请选择使用人'
				//	});
				//	return;
				//}
				
				var currtime = (self.getDateDay());
				var _newDataArr = [];
				var _newDataObj = {};

				_newDataObj['checkPosition'] =self.inputzcwzid;				
				_newDataObj['documentId'] =newDocumentId;
				//_newDataObj['taskId'] ="ECEA7313-DAEB-4C6F-A07A-EDD9894AD552";
				
				_newDataObj['assetName'] = self.assetName;
				_newDataObj['realityUsingUser'] = self.loginid;
				//_newDataObj['盘点人'] = userdata.LoginName;
				//_newDataObj['盘点状态'] = "已盘";
				_newDataObj['checkResult'] = "3";
				//_newDataObj['盘点结果'] = "盘盈";
				_newDataObj['model'] = self.GGXH //GGXH;
				//GGXH
				_newDataObj['checkDate'] = self.iputewdate;
				_newDataObj['checkDescription'] = self.assetDescription;
				_newDataObj['assetCategory'] = self.inputzclbid;
				_newDataObj['realityUsingUser'] = self.assetUsingName;
				//_newDataObj['usingOrg'] = self.inputsybm;
				//_newDataObj['usingUser'] = self.inputsyr; 
				_newDataObj['realityCheckUser'] = self.loginid;//实际盘点人ID
				_newDataObj['realityCheckUserOrgId'] = self.loginorgId;//实际盘点人部门ID
				if(self.srcstring!="../../static/images/icon-paizhao.png"){
					_newDataObj['attachFiles'] = self.srcstring;
				}else{
				if(self.isPhoto=="1"){
					uni.showToast({
						icon: 'none',
						title: '请上传盘点图片'
					});
					return;
				}
				}
				//_newDataObj['realityUsingUser'] = self.inputsyr;//实际使用人
				_newDataArr.push(_newDataObj);
				console.log(_newDataArr);
				//var str1 = JSON.stringify(_newDataArr);
			
			
				this.request_tool({
					url:'/console/app/v1/assetCheck/checkHandleAsset',
					type:'POST',
					data:_newDataArr
				}).then(res => {
					console.error(res);
					if (res.data.code == 2000) {
							
						var yyshul=parseInt(this.documentmodel.盘盈)+1;
						
						
						var updateSQL = 'update MybuildTable set StockCheckResult="1",盘盈="'+yyshul+'" where Id="'+newDocumentId+'"';
							console.log(updateSQL);  
							executeSQL('nfc', updateSQL, res => {  
								console.log("已更新列表数据");
								uni.setStorage({
									key: 'documentRefresh',
									data: '1'
								});
								console.log(111);
								
								var sqlInsert = "insert into buildDetailTable values('";
								sqlInsert += self.getGuid()+"','";
								sqlInsert += newDocumentId + "','";
								sqlInsert += self.getGuid()+"','";
								sqlInsert += self.inputzcwz+"','";
								sqlInsert += self.inputzcwz + "','";
								sqlInsert +=  "','";
								sqlInsert += self.inputzcwz +"','";
								sqlInsert += "','";
								sqlInsert +=  "','";
								sqlInsert += self.assetName + "','";
								sqlInsert +=  self.inputzclb + "','";
								sqlInsert += self.GGXH + "','";
								sqlInsert +=  "1','";
								sqlInsert += self.documentmodel.盘点单名称.split("_")[0] + "','";
								sqlInsert +=""+ "','";
								sqlInsert += self.assetUsingName + "','";
								sqlInsert +=  self.inputzcwz+"','";
								sqlInsert += self.inputzcwz + "','";
								sqlInsert += self.assetDescription + "','";
								sqlInsert += username + "','";
								sqlInsert +=  "已盘','";
								sqlInsert +=  "盘盈','";
								sqlInsert += self.iputewdate + "','";
								sqlInsert += self.srcstring + "','";
								sqlInsert += 0 + "','";
								sqlInsert +=  "0'";
								sqlInsert += ')';
								console.log(sqlInsert);
								executeSQL('nfc', sqlInsert, res45 => {
									console.log("已更新列表数据22");
								uni.setStorageSync("pdsys","1");
								uni.navigateTo({
									url: '../stock/StockDocumentDetail?id=' + newDocumentId,
									animationType:'slide-in-left',
										animationDuration: 500
								});		
								});
								
								
								
							})
						
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});							
						}
					}).catch(err => {
			  console.error(err);
			  
			});
			
							/*
				uni.request({
					url: uni.getStorageSync("localurl") +
					'/ServerAPI/AppDocument_SaveFinished_Add', //仅为示例，并非真实接口地址。
					data: {
						Id: newDocumentId,
						datastr: str1
					},
					method: "POST",
					success: res2 => {

						if (res2.data.successed == true) {
							var yyshul=parseInt(this.documentmodel.盘盈)+1;
							
							
							var updateSQL = 'update MybuildTable set StockCheckResult="1",盘盈="'+yyshul+'" where Id="'+newDocumentId+'"';
								console.log(updateSQL);  
								executeSQL('nfc', updateSQL, res => {  
									console.log("已更新列表数据");
									uni.setStorage({
										key: 'documentRefresh',
										data: '1'
									});
									console.log(111);
									var sqlInsert = "insert into buildDetailTable values('";
									sqlInsert += "00000000-0000-0000-0000-000000000000','";
									sqlInsert += newDocumentId + "','";
									sqlInsert += "00000000-0000-0000-0000-000000000000','";
									sqlInsert +=  "00000000-0000-0000-0000-000000000000','";
									sqlInsert += self.inputzcwzid + "','";
									sqlInsert +=  "','";
									sqlInsert += "','";
									sqlInsert += "','";
									sqlInsert +=  "','";
									sqlInsert += self.assetName + "','";
									sqlInsert +=  self.inputzclb + "','";
									sqlInsert += self.GGXH + "','";
									sqlInsert +=  "1','";
									sqlInsert += self.inputsybm + "','";
									sqlInsert +=self.inputsyr + "','";
									sqlInsert += "" + "','";
									sqlInsert +=  self.inputzcwz+"','";
									sqlInsert += self.inputzcwz + "','";
									sqlInsert += self.assetDescription + "','";
									sqlInsert += userdata.LoginName + "','";
									sqlInsert +=  "已盘','";
									sqlInsert +=  "盘盈','";
									sqlInsert += self.iputewdate + "','";
									sqlInsert += "" + "','";
									sqlInsert +=  "1'";
									sqlInsert += ')';
									console.log(sqlInsert);
									executeSQL('nfc', sqlInsert, res45 => {
										console.log("已更新列表数据22");
									uni.setStorageSync("pdsys","1");
									uni.navigateTo({
										url: '../stock/StockDocumentDetail?id=' + newDocumentId,
										animationType:'slide-in-left',
										    animationDuration: 500
									});		
									});
									
									
									
								})
							
							//uni.setStorageSync("pdsys", "1");
							//uni.navigateTo({
							//	url: '../stock/StockDocumentDetail?id=' + newDocumentId,
							//	animationType: 'slide-in-left',
							//	animationDuration: 500
							//});
							//this.model = res.data.model;
						} else {
							uni.showModal({
								title: '提示',
								content: res2.data.responseState,
								showCancel: false,
								success: function(res) {
									if (res.confirm) {

									}
								}
							});
						}
					},
					fail: () => {

						uni.showToast({
							icon: 'none',
							title: '网络异常,请稍后重试'
						});
					}
				});
*/


			}
		},
		onLoad(options) {
			//首先将实例指针保存到全局变量 self 方便在异步请求中访问实例本身
			self = this;
			
			const newDocumentId = uni.getStorageSync('DocumentId');
			self.DocumentId=newDocumentId;
			self.iputewdate = self.getDateDay();
			const userinfo = uni.getStorageSync("userInfo");
			this.loginid=JSON.parse(userinfo).id;
			this.loginorgId=JSON.parse(userinfo).orgId;
			this.loginName = JSON.parse(userinfo).loginName;
			console.log(JSON.parse(userinfo).userName);
			self.optiontype=options.type;
			
			console.log(self.getDateDay());
			
			let querydata={
					//"pageSize": 10,
					//"current": 0,
					manageUser:JSON.parse(userinfo).id
				};
			this.request_tool({
				url:'/console/app/v1/assetCheck/getCheckDocumentListAndTaskList',
				type:'POST', 
				data:querydata
			}).then(res => {
				console.log(res);		
					if(res!=undefined){
							}else{
								self.isrequest=false;
								
							}
			}).catch(err => {
			  
			  
			});
			
			
			var sql3="select * from MybuildTable where 1=1 and Id='"+newDocumentId+"'";
			executeSQL('nfc', sql3, res => {
				//this.productList = mydata;
				// 接口返回的当前页数据列表 (数组)
				console.log(res);
				if(res.code!=-1404){
					var mydata = [];
					if (res.length > 0) {
						self.documentmodel = res[0];
						console.log(self.documentmodel);
						console.log(self.documentmodel.盘点单名称.split("_")[0]);
					}
						
					}else{												
						self.mescroll.endSuccess(0);
							//设置列表数据
						self.goods = []; //追加新数据
							setTimeout(() => {
						self.mescroll.endSuccess(0)
							}, 20)
											
					}
				
			});
			
		},
		methods: {
			getbt(){
				if(this.isPhoto=="1"){
					return this.scrbt;
				}else{
					return "";
					}
					
				
			},
			getvalues(){
				
					//console.log('http://47.100.57.58:9000/'+value[0].realUrl);
					if(this.srcstring=="../../static/images/icon-paizhao.png"){
						return this.srcstring;
					}else{
						if(this.srcstring.indexOf("gdzcfile")>-1){
							return uni.getStorageSync("localurlfileurl")+this.srcstring;
						}else{
							return this.srcstring;
						}
					}
					
				
			},			
			S4() {
			  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
			},
			getGuid(){
				let guid=(this.S4() + this.S4() + '-' + this.S4() + '-' + this.S4() + '-' + this.S4() + '-' + this.S4() + this.S4() + this.S4());
				return guid;
				
			},
			uploadimg() {
				self = this;
				
				// 只允许通过相机扫码
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['camera'],
					success: function(res) {
							// 预览图片
							this.images = res.tempFilePaths;
							const mysrc = res.tempFilePaths[0];
							console.log(mysrc);
							if(self.isrequest){
							const tempFilePaths = res.tempFilePaths;
								
							const header={
								'Content-Type':'application/json',
								Authorization: uni.getStorageSync("authorization")
							};
								console.log(tempFilePaths[0]);
								uni.compressImage({
								      src: tempFilePaths[0], // 图片路径
								      //quality: 80, // 压缩质量，范围为0 - 100，100为不压缩
									 quality: 50, //压缩比例  图片质量[10-100]
									//overwrite: true,
								      success: function (res3) {
								        // 获取压缩后的图片路径
										 console.log(res3)
								        var compressedFilePath = res3.tempFilePath
								        console.log('压缩后的图片路径：' + compressedFilePath)
										uni.uploadFile({
										  url: uni.getStorageSync("localurl")+'/console/app/v1/fileOss/upload', // 你的上传API地址
										  filePath: tempFilePaths[0],
										  name: 'file',
										header: header, // 设置请求的 header
										  formData: {
											// 其他要上传的参数
											file:{}
										  },
										  success: (uploadRes) => {
											console.log('图片上传成功', uploadRes);	
											let uploadResdata= JSON.parse(uploadRes.data);
											if(uploadResdata.code==2000){
											
											console.log(uploadResdata);
											self.srcstring=uploadResdata.data;
											}else{
												uni.showToast({
													icon: 'none',
													title: uploadResdata.msg
												});							
											}											
											
										  },
										  fail: (uploadErr) => {
											console.log('上传失败', uploadErr);
										  }
										});
									},
									fail: (uploadErr) => {
											console.log('压缩失败', uploadErr);
									},
									});
						}else{
							self.srcstring=mysrc;
						}
					}
				});
			},
			isanAsset(e) {
				//console.log(e.currentTarget.dataset.id);
				console.log(112222);
				uni.navigateTo({
					url: '../asset/asset?Id=' + e.currentTarget.dataset.id,
				});
			},
			getTime: function() {

				var date = new Date(),
					year = date.getFullYear(),
					month = date.getMonth() + 1,
					day = date.getDate(),
					hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
					minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
					second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				month >= 1 && month <= 9 ? (month = "0" + month) : "";
				day >= 0 && day <= 9 ? (day = "0" + day) : "";
				//var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
				//return timer;
				var timer = year + '-' + month + '-' + day;
				return timer;
			},
			getDateDay() {
				var myDate = new Date();
				console.log(myDate);
				var year = myDate.getFullYear(); //获取当前年
				var month = myDate.getMonth() + 1; //获取当前月
				var date = myDate.getDate(); //获取当前日


				var now = year + '' + this.getNow(month) + "" + this.getNow(date);
				return now;
			},
			getDateDayStr(Str) {
				console.log(Str);
				if(Str.indexOf("-")==-1){
					return Str.substr(0,4)+"-"+Str.substr(4,2)+"-"+Str.substr(6,2);
				}else{
					return Str;
				}
			},
			getNow(s) {
				return s < 10 ? '0' + s : s;
			},
			focusshow(e) {
				this.selectvalue = e.currentTarget.dataset.id;
				this.treelist = [];
				this.$refs.tkitree.oldtreeList = "";
				this.$refs.tkitree.servalue = "";

				if (e.currentTarget.dataset.id == "zclb") {
					this.showTree();
					this.title = "请选择资产类别";
					this.loadAssetType();
				} else if (e.currentTarget.dataset.id == "zcwz") {
					this.showTree();
					this.title = "请选择资产位置";
					this.loadStoreplase();
				} else if (e.currentTarget.dataset.id == "sybm") {
					this.showTree();
					this.title = "请选择使用部门";
					this.loadDepartment();
				} else if (e.currentTarget.dataset.id == "syr") {
					if (this.inputsybmid == "" || this.inputsybmid == null) {
						uni.showToast({
							icon: 'none',
							title: '请选择使用部门'
						});
						return;
					} else {
						this.showTree();
						this.title = "请选择使用人";
						this.loadsybmProfile();
					}
				}

			},
			// 确定回调事件
			treeConfirm(e) {
				this.showTreeValue = false;
				console.log(this.selectvalue);
				if (this.selectvalue == "zclb") {
					this.inputzclb = e[0].label;
					this.inputzclbid = e[0].id;
					
					let assetCategoryPhoto = uni.getStorageSync(self.DocumentId+"assetCategoryPhoto");
					if(assetCategoryPhoto.includes(e[0].id)){
						this.isPhoto="1";
					}
					
					
				} else if (this.selectvalue == "zcwz") {
					this.inputzcwz = e[0].label;
					this.inputzcwzid = e[0].id;
				} else if (this.selectvalue == "pdzcwz") {
					console.log(e[0].id);
					uni.setStorageSync("CurrStore", e[0].id);
					uni.setStorageSync("CurrStoreName", e[0].label);
					this.inputpdzcwz = e[0].label;
					this.inputpdzcwzid = e[0].id;
				} else if (this.selectvalue == "sybm") {
					this.inputsybm = e[0].label;
					this.inputsybmid = e[0].id;
				} else if (this.selectvalue == "syr") {
					this.inputsyr = e[0].label;
					this.inputsyrid = e[0].id;
				}

			},
			// 取消回调事件
			treeCancel(e) {
				this.showTreeValue = false;
				console.log(e)
			},
			treekeyinput(value){
				let bmid="";
				if(this.selectvalue=="zrr"){
					bmid=this.inputglbmid;
				}
				if(this.selectvalue=="syr"){
					bmid=this.inputsybmid;
				}
				
				this.request_tool({
					url:'/console/app/v1/operator/pageData',
					type:'POST',
					data:{"orgId":bmid,"userName":value,"current":0,"pageSize":100}
				}).then(res => {
						//console.error(res);
						if(res!=undefined){
							if (res.data.code == 2000) {
								//console.log(res.data.data);
								//self.treelist= res.data.data;
								let newtreelist=[];
								for(var i=0;i<res.data.data.records.length;i++){
									let resitem= res.data.data.records[i];
									let treeitem={
										id:resitem.id,
										label:resitem.userName,
										isEnabled:resitem.isEnabled,
										checked:false,
										children:[],
									};
									newtreelist.push(treeitem);
								}
								self.treelist=newtreelist;
								setTimeout(function () {
								  uni.hideNavigationBarLoading();
								}, 2000);
								this.$refs.tkitree.oldtreeList="";
								this.$refs.tkitree.servalue=value;
								this.showTree();
								//this.model = res.data.model;
							}else{
								uni.showToast({
									icon: 'none',
									title: res.data.msg
								});							
							}
						}
						}).catch(err => {
				  console.error(err);
				  
				});
				
				//this.treelist=newtreeList;
			},
			// 显示树形选择器
			showTree() {
				this.showTreeValue = true;
				this.$refs.tkitree._show();
			},
			loadAssetType() {
				self = this;

				uni.showNavigationBarLoading();
				uni.showNavigationBarLoading();
				this.request_tool({
					url:'/console/app/v1/asset-category/treeData',
					type:'POST',
					data:{}
				}).then(res => {
						console.error(res);
						if (res.data.code == 2000) {
							console.log(res.data.data);
							self.treelist= res.data.data;
							setTimeout(function () {
							  uni.hideNavigationBarLoading();
							}, 2000);
							this.$refs.tkitree.oldtreeList="";
							this.$refs.tkitree.servalue="";
							this.showTree();
							//this.model = res.data.model;
						}else{
								uni.showToast({
									icon: 'none',
									title: res.data.msg
								});							
							}
						}).catch(err => {
				  console.error(err);
				  
				});

			},
			loadStoreplase() {
				self = this;

				uni.showNavigationBarLoading();
				let sql = "select * from buildStore";
				console.log(sql);
				executeSQL('nfc', sql, res => {
					//this.productList = mydata;
					// 接口返回的当前页数据列表 (数组)
					if(res.code!=-1404){
						
						if(res.length>0){
							let mydata=res;
							//self.treelist=JSON.parse(res[0]["value"]);
							//console.log(self.treelist);
							let treedata=JSON.parse(res[0]["value"]);
							let managePositionIds=JSON.parse(self.documentmodel.orgPosition);
							
							let newtreedata=[];
							self.filterParentNode(managePositionIds,treedata,newtreedata);
							self.treelist=newtreedata;
							setTimeout(function() {
								uni.hideNavigationBarLoading();
							}, 1000);
						}
					}
				})

			},
			loadDepartment() {
				self = this;
				uni.showNavigationBarLoading();
				this.request_tool({
					url:'/console/app/v1/organization/treeData',
					type:'POST',
					data:{}
				}).then(res => {
						console.error(res);
						if (res.data.code == 2000) {
							console.log(res.data.data);
							self.treelist= res.data.data;
							setTimeout(function () {
							  uni.hideNavigationBarLoading();
							}, 2000);
							this.$refs.tkitree.oldtreeList="";
							this.$refs.tkitree.servalue="";
							this.showTree();
							//this.model = res.data.model;
						}else{
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});							
						}
						}).catch(err => {
				  console.error(err);
				  
				});
			},
			loadsybmProfile(){
				self=this;
				uni.showNavigationBarLoading();
				self.request_tool({
					url:'/console/app/v1/operator/pageData',
					type:'POST',
					data:{"orgId":self.inputsybmid,"current":0,"pageSize":100}
				}).then(res => {
						console.error(res);
						if(res!=undefined){
						if (res.data.code == 2000) {
							console.log(res.data.data);
							//self.treelist= res.data.data;
							let newtreelist=[];
							for(var i=0;i<res.data.data.records.length;i++){
								let resitem= res.data.data.records[i];
								let treeitem={
									id:resitem.id,
									label:resitem.userName,
									isEnabled:resitem.isEnabled,
									checked:false,
									children:[],
								};
								newtreelist.push(treeitem);
							}
							self.treelist=newtreelist;
							setTimeout(function () {
							  uni.hideNavigationBarLoading();
							}, 2000);
							this.$refs.tkitree.oldtreeList="";
							this.$refs.tkitree.servalue="";
							this.showTree();
							//this.model = res.data.model;
						}else{
								uni.showToast({
									icon: 'none',
									title: res.data.msg
								});							
							}
						}
						}).catch(err => {
				  console.error(err);
				  
				});
				
			},
			filterParentNode(ids,options,options2){
			      if(Array.isArray(ids)&&ids.length>0){
			        options.forEach(option=>{	
						if(ids.includes(option.id)){
							let newoption={
								"id": option.id,
								"code": option.code,
								"label": option.label,
								"isEnabled": option.isEnabled,
								"levelCode": option.levelCode,
								"parentLevelCode": option.parentLevelCode,
								"pathCode": option.pathCode,
								"entityName": option.entityName,
							}							
							let childrenarr=[];
							if(option.children){
							  this.filterParentNode(ids,option.children,childrenarr);
							}
							newoption.children=childrenarr;
							
							options2.push(newoption);
						}else{							
								if(option.children){
									let childrenarr=[];
								  this.filterParentNode(ids,option.children,childrenarr);
								  if(childrenarr.length>0){
									  let newoption={
									  	"id": option.id,
									  	"code": option.code,
									  	"label": option.label,
									  	"isEnabled": "0",
									  	"levelCode": option.levelCode,
									  	"parentLevelCode": option.parentLevelCode,
									  	"pathCode": option.pathCode,
									  	"entityName": option.entityName,
									  }
										newoption.children=childrenarr;
										options2.push(newoption);
								  }
								}
							}
			         
			        });
			      }
			    },
			request_tool(options){
			 // 在这里可以对请求头进行一些设置
			 let baseUrl = uni.getStorageSync("localurl"); 
			
			  options.header = {
			      'Content-Type':'application/json',
			      Authorization: uni.getStorageSync("authorization")
			 }
			
			    return new Promise((resolve, reject) => {
			        uni.request({
			            url: baseUrl + options.url || '',
			            method: options.type || 'POST',
			            data: options.data || {},
			            header: options.header || {}      
			        }).then(data => {
			            let [err, res] = data;        
			            resolve(res);
			        }).catch(error => {
			            reject(error)
			        })
			    });
			}
		}

	}
</script>

<style>
	.item-icon-bt {
		width: 30upx;
		height: 30upx;
	}

	.item-icon-sys {
		width: 40upx;
		height: 40upx;
	}

	.item-icon {
		width: 100upx;
		height: 100upx;
	}

	.Item {
		border-radius: 16rpx;
		background: #fff;
	}

	.item-text {
		border-bottom: 1px solid #e6e6e6;
		margin-right: .8rem;
		margin-left: .8rem;
	}

	.item-text .span {
		display: inline-block;
		width: 67%;
		float: right;
		margin-bottom: 10rpx;
		text-align: right;
		color: #000;
	}

	.item-text .ispan {
		font-style: normal;
		width: 30%;
		display: inline-block;
		margin-bottom: 10rpx;
		color: #BEBEBE;
		
	}

	.Item input {
		font-size: 30rpx;
	}

	.inputff {
		font-size: 30rpx;
	}



	.item-content {
		padding-left: 0;
	}

	.item-title .ispan {
		font-size: 30rpx;
		width: auto;
		height: auto;
	}

	.item-title {
		font-size: 30rpx;
		color: #454545;
		width: 50%;
		height: 80rpx;
		line-height: 80rpx;
		margin-left: 30rpx;
	}

	.item-title-row {
		background-image: none;
		margin-right: .8rem;
		border-bottom: 1px solid #e6e6e6;
		background-color: #F4F5F6;
		margin-left: .8rem;
	}


	.item-link .item-inner {
		padding-right: 0;

	}

	.page-content {
		padding-top: 0;
	}

	.item-text {
		font-size: 30rpx;
		color: #454545;
		padding: 20rpx 0;
		padding-left: 0rpx;
		line-height: 1.2;
	}

	.btext {
		font-weight: normal;
		color: #F79D63;
	}

	.scroll-view_H {
		white-space: nowrap;

		.scroll-view-item_H {
			display: inline-block;
			width: 100%;
			height: 100px;
		}

		.uni-bg-red {
			background: red;
		}

		.uni-bg-green {
			background: green;
		}

		.uni-bg-blue {
			background: blue;
		}
	}

	.yp-Item-span {
		position: absolute;
		width: 50rpx;
		background-color: #BEBEBE;
		font-size: 25rpx;
		padding: 0 10rpx;
		margin-right: 10rpx;
		text-align: center;
		margin-left: 35rpx;
		margin-top: 24rpx;
		color: #FFFFFF;
		border-radius: 8rpx;
	}

	.wp-Item-span {
		position: absolute;
		width: 50rpx;
		background-color: #6D8AF9;
		font-size: 25rpx;
		padding: 0 10rpx;
		margin-right: 10rpx;
		text-align: center;
		margin-left: 35rpx;
		margin-top: 24rpx;
		color: #FFFFFF;
		border-radius: 8rpx;
	}
</style>
